<script>
import * as echarts from 'echarts';
export default {
  name: "index",
  data(){
    return{
    }
  },
  mounted() {
    let nameList = ['第一名', '第二名', '第三名', '第四名', '第五名'];
    let dataList = [20001, 15000, 8000, 7500, 5000];
    let chartDom = document.getElementById('main');
    let myChart = echarts.init(chartDom);
    let option;
    option = {
      title: [
        {
          text: '仓库金额排行'
        }
      ],
      color: ['#7F8AF2'],
      grid: {
        left: '5%',
        right: '5%',
        top: '10%',
        bottom: '0',
        containLabel: true
      },
      xAxis: {
        show: false,
        type: 'value'
      },
      yAxis: [
        {
          show: true,
          type: 'category',
          axisTick: {
            // 轴刻度线
            show: false
          },
          axisLine: {
            // 轴
            show: false
          },
          inverse: 'true', // 排序,
          axisLabel: {
            show: true,
            inside: true,
            interval: 0, //横轴信息全部显
            splitNumber: 50,
            color: '#333333',
            verticalAlign: 'bottom',
            fontSize: 15,
            align: 'left',
            padding: [0, 0, 12, -5]
          },
          data: nameList
        },
        {
          type: 'category',
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            show: true,
            inside: false,
            color: '#021C38',
            fontSize: '14',
            formatter: function (v) {
              return v + '元';
            }
          },
          splitArea: {
            show: false
          },
          splitLine: {
            show: false
          },
          inverse: 'true', // 排序
          data: dataList
        }
      ],
      series: [
        {
          inverse: 'true', // 排序
          data: dataList,
          type: 'bar',
          showBackground: true,
          backgroundStyle: {
            borderRadius: 40
          },
          barWidth: '15',
          itemStyle: {
            borderRadius: 10
            // color: (param) => {
            //   //实现柱状图条 下面四种颜色循环显示
            //   let colorList = ['#e74c3c','#ffa865', '#f8d26b', '#74dcc4', '#47c0ff']
            //   return colorList[param.dataIndex % 5]
            // }
          }
        }
      ]
    };
    option && myChart.setOption(option);


  }
}
</script>

<template>
  <div class="box">
    <div id="main" style="width: 80vw;height: 60vh"></div>
  </div>
</template>

<style scoped lang="scss">
.box{
  margin: 0 auto;
  padding: 20px;
}
</style>
